﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SignalShopBase;

namespace TestModule
{
    public class T2FModule : SignalShopModule
    {
        public T2FModule() : base(NAME, PATH) { }

        public override void Execute(Signal target, Signal source)
        {
            int N = target.N;

            Signal temp = new Signal(N);
            Complex sum = new Complex();
            Complex c = new Complex();

            for (int f = -N; f <= N; f++)
            {
                sum.Set(0.0, 0.0);
                double w = 2.0 * Math.PI * f;

                for (int n = -N; n <= N; n++)
                {
                    double t = (1.0 * n) / (2 * N + 1);
                    sum.Add(c.Set(target[n]).Rot(-1.0 * w * t));
                }

                temp[f].Set(sum).Mul(1.0 / (2 * N + 1));
            }

            for (int n = -N; n <= N; n++)
            {
                target[n].Set(temp[n]);
            }
        }

        private const string NAME = "T2F";
        private const string PATH = "Transform/T2F";
    }
}
